package org.coding.springbootdemowebmvc.config;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * @auth guoxh
 * @date 2020/10/17 4:33 下午
 * @desc
 **/
public class InterfaceProxy implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getName();
        String param = Arrays.toString(args);
        return param;
    }

    public static <T> T newInstance(Class<T> innerInterface){
        ClassLoader classLoader = innerInterface.getClassLoader();
        Class[] interfaces = new Class[]{innerInterface};
        InterfaceProxy proxy = new InterfaceProxy();
        return (T) Proxy.newProxyInstance(classLoader,interfaces,proxy);
    }
}
